package com.suxii.todomvi.data.local

import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Update
import com.suxii.todomvi.domain.model.Todo
import kotlinx.coroutines.flow.Flow

@Dao
interface TodoDao {

    // 新增，如果id冲突就替换
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun insert(todo: Todo)

    @Update
    suspend fun update(todo: Todo)

    @Delete
    suspend fun delete(todo: Todo)

    @Query("delete from tb_todo where id in(:ids)")
    suspend fun deleteByIds(ids:Set<Int>)

    @Query("select * from tb_todo")
    fun queryAll():Flow<List<Todo>>
}